package site.anxuan.seckill.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.sql.Timestamp;

/**
 * 秒杀活动实体类
 *
 * @author 黯玄
 * @since v1.0
 */
@Data
@ToString
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class Promotion {

    /** 主键 */
    private Integer id;

    /** 商品实体类主键 */
    private Integer itemId;

    /** 活动名称 */
    private String name;

    /** 活动开始时间 */
    private Timestamp startTime;

    /** 活动结束时间 */
    private Timestamp endTime;

    /** 活动价 */
    private BigDecimal promotionPrice;

    /**
     * 获取活动状态
     *
     * @return -1: 活动未开始, 0: 活动进行中, 1: 活动已结束.
     */
    public int getStatus() {
        Timestamp now = new Timestamp(System.currentTimeMillis());
        if (now.before(startTime)) {
            return -1;
        } else if (now.after(endTime)) {
            return 1;
        } else {
            return 0;
        }
    }

}
